// 商品模型
const { Goods } = require('../../../models/good');
// 统一数据返回类
const { DataReturn } = require('../../../common/returnclass');

module.exports = async (req, res) => {
	// 搜索名称 当前页  商品名称 
	let { pagenum, goods_name } = req.query;
	console.log(req.query);
	// 查询条数
	let pagesize = 10;

	// 查询所有商品信息
	goods = await Goods.find({goods_name: { $regex: goods_name,$options:"$i" }}).select('-goods_content').skip(pagesize*(pagenum-1)).limit(pagesize);
	if (!goods) return DataReturn.getData(res, 200, goods, '暂无商品数据');
	// 响应
	DataReturn.getData(res, 200, { goods:goods, total: await Goods.find({goods_name: { $regex: goods_name,$options:"$i" }}).countDocuments() }, '查询商品列表成功')

}
